<!DOCTYPE html>
<html lang='en'>
<head>
<meta charset='UTF-8'>
<meta name='viewport' content='width=device-width, initial-scale=1.0'>
<title>Document</title>
</head>
<body>

  <div id='app'>
    <home></home>
  </div>
  

<script src='https://cdn.bootcdn.net/ajax/libs/vue/2.6.12/vue.js'></script>
<script>
  const Home = {
    template: `
      <div>
        Home组件
        <input v-model="msg" />
        <button @click="add">按钮</button>
        <ul>
          <li v-for="item in arr" :key="item">{{item}}</li>
        </ul>
      </div>
    `
    ,data () {
      return {
        msg: '组件生命周期'
        ,arr: [1,2,3]
      }
    }
    ,methods: {
      add() {
        this.arr.push(this.arr.length+1)
      }
    }
    ,beforeCreate() {
      console.log('实例创建完成之前');
    }
    ,created() {
      console.log('实例创建完成，组件的属性和方法已经可以调用，且数据已经变成响应式');
    }
    ,beforeMount() {
      console.log('组件模板渲染之前');
    }
    ,mounted() {
      console.log('组件模板渲染完成， 可以获取DOM');
      console.log( document.querySelector('button') );
    }
    ,beforeUpdate() {
      console.log('组件更新之前');
    }
    ,updated() {
      console.log('组件更新完成，可以获取最新DOM');
      console.log(document.querySelectorAll('li'));
    }
    ,beforeDestroy(){
      console.log('组件销毁之前');
    }
    ,destroyed() {
      console.log('组件销毁');
    }
  }
  Vue.component("Home", Home)
  const app = new Vue({
    el: '#app'
  })
</script>
</body>
</html>